package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.util.StringUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.util.ShippingAddressStatusEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;

public class FollowedShippingAddressUpdateRequest extends Request {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8299332645438508192L;

private int id = 0;
	
    private String userId ;

    private String province;
    
    private String name;

    private String city;

    private String district;

    private String street;

    private String fullAddress;

    private String contacts;

    private String contactNumber;

    private String postcode;

    private int isDefault = ShippingAddressStatusEnum.STATUS_NOT_DEFAULT.getId();//是否为默认地址

    private int isPrivacyReceipt = ShippingAddressStatusEnum.STATUS_NOT_PRIVACY_RECEIPT.getId();//非隐私收件

    private int isTemporaryAddress = ShippingAddressStatusEnum.STATUS_NOT_TEMP_ADDR.getId();//非临时地址

    private int rank = 0;

    private int status = ShippingAddressStatusEnum.STATUS_NOT_DELETE.getId();//使用状态
    
    private String areaId;
    
	private String telNumber;

	@Override
	public void parse(HttpServletRequest request) {
		
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		this.id = requestInfo.getIntParameter(ApiUrlParamEnum.userShippingAddressId.getParamName(), -1);
		if( id < 1 ) {
			throw new RequestIllegalException("error addressId:"+id);
		}
		
		this.userId = requestInfo.getParameter(ApiUrlParamEnum.userId.getParamName(),"");
		if ( userId.equals("")) {
			throw new RequestIllegalException("error userId is null");
		}
		
		this.province = requestInfo.getParameter(ApiUrlParamEnum.province.getParamName(), "");
		if ( StringUtil.isEmpty(province) ) {
			throw new RequestIllegalException("error province is null ");
		}
		
		this.city = requestInfo.getParameter(ApiUrlParamEnum.city.getParamName(), "");
		if ( StringUtil.isEmpty(city) ) {
			throw new RequestIllegalException("error city is null ");
		}
		
		this.district = requestInfo.getParameter(ApiUrlParamEnum.district.getParamName(), "");
		if ( StringUtil.isEmpty(district) ) {
			throw new RequestIllegalException("error district is null ");
		}
		
		this.street = StringUtil.fixHtml(requestInfo.getParameter(ApiUrlParamEnum.street.getParamName(), ""));
		this.contacts = StringUtil.fixHtml((requestInfo.getParameter(ApiUrlParamEnum.contacts.getParamName(), "")));
		this.areaId = requestInfo.getParameter(ApiUrlParamEnum.areaCode.getParamName(), "");
		if ( StringUtil.isEmpty(areaId) ) {
			throw new RequestIllegalException("error areaId is null ");
		}
		
		this.contactNumber = requestInfo.getParameter(ApiUrlParamEnum.contactNumber.getParamName(), "");
		this.telNumber = requestInfo.getParameter(ApiUrlParamEnum.telNumber.getParamName(), "");
		
		if(!StringUtil.isEmpty(contactNumber) && (contactNumber.length() < 11 || !StringUtil.isMobilePhone(contactNumber))){
			throw new RequestIllegalException("手机号码格式错误 :"+contactNumber);
		}
		
		this.fullAddress = new StringBuilder(this.province).append(this.city).append(this.district).append(this.street).toString();
		
		this.postcode = requestInfo.getParameter(ApiUrlParamEnum.postcode.getParamName(), "");
		if(!StringUtil.isEmpty(postcode) && postcode.length() < 6){
			throw new RequestIllegalException("error postcode length too short :"+postcode);
		}
		
		this.isDefault = requestInfo.getIntParameter(ApiUrlParamEnum.isDefault.getParamName() ,ShippingAddressStatusEnum.STATUS_NOT_DEFAULT.getId() );
		
		this.isPrivacyReceipt = requestInfo.getIntParameter(ApiUrlParamEnum.isPrivacy.getParamName() ,  ShippingAddressStatusEnum.STATUS_NOT_PRIVACY_RECEIPT.getId());
		this.isTemporaryAddress = requestInfo.getIntParameter(ApiUrlParamEnum.isTemporaryAddress.getParamName() ,  ShippingAddressStatusEnum.STATUS_NOT_TEMP_ADDR.getId());
		this.rank = requestInfo.getIntParameter(ApiUrlParamEnum.rank.getParamName(),0);
		this.status = requestInfo.getIntParameter(ApiUrlParamEnum.status.getParamName() , ShippingAddressStatusEnum.STATUS_NOT_DELETE.getId());
		this.name = StringUtil.fixHtml(requestInfo.getParameter(ApiUrlParamEnum.name.getParamName(), ""));
		
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getProvince() {
		return province;
	}

	public void setProvince(String province) {
		this.province = province;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getDistrict() {
		return district;
	}

	public void setDistrict(String district) {
		this.district = district;
	}

	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public String getFullAddress() {
		return fullAddress;
	}

	public String getContacts() {
		return contacts;
	}

	public void setContacts(String contacts) {
		this.contacts = contacts;
	}

	public String getContactNumber() {
		return contactNumber;
	}

	public void setContactNumber(String contactNumber) {
		this.contactNumber = contactNumber;
	}

	public String getPostcode() {
		return postcode;
	}

	public void setPostcode(String postcode) {
		this.postcode = postcode;
	}

	public int getIsDefault() {
		return isDefault;
	}

	public void setIsDefault(int isDefault) {
		this.isDefault = isDefault;
	}

	public int getIsPrivacyReceipt() {
		return isPrivacyReceipt;
	}

	public void setIsPrivacyReceipt(int isPrivacyReceipt) {
		this.isPrivacyReceipt = isPrivacyReceipt;
	}

	public int getIsTemporaryAddress() {
		return isTemporaryAddress;
	}

	public void setIsTemporaryAddress(int isTemporaryAddress) {
		this.isTemporaryAddress = isTemporaryAddress;
	}

	public int getRank() {
		return rank;
	}

	public void setRank(int rank) {
		this.rank = rank;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}
	
	public String getName() {
		return this.name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getAreaId() {
		return areaId;
	}

	public void setAreaId(String areaId) {
		this.areaId = areaId;
	}

	public String getTelNumber() {
		return telNumber;
	}

	public void setTelNumber(String telNumber) {
		this.telNumber = telNumber;
	}

	public void setFullAddress(String fullAddress) {
		this.fullAddress = fullAddress;
	}
}
